package ztc.servlet;

import ztc.common.StuBean;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.concurrent.ConcurrentHashMap;
import java.io.IOException;


/**
 * Created by ztc on 16-4-6.下午6:21
 */
public class QRSiginin extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        if(request.getParameter("uuid")!=null){
            request.setCharacterEncoding("utf-8");
            String uuid=request.getParameter("uuid");
            String sessionID=request.getParameter("sessionID");
            String stuID=request.getParameter("stuID");
            String name=request.getParameter("name");
            String sex=request.getParameter("sex");
            String classs=request.getParameter("classs");
            String institute=request.getParameter("institute");
            String mac=request.getParameter("mac");

            ServletContext application=this.getServletContext();
            ConcurrentHashMap<String,ConcurrentHashMap<String,StuBean>> aMap=
                    (ConcurrentHashMap<String, ConcurrentHashMap<String, StuBean>>) application.getAttribute("sessionID");
            ConcurrentHashMap<String,StuBean> sMap=
                    aMap.get(sessionID);
            if(sMap!=null&&sMap.containsKey(uuid)&&sMap.get(uuid).getName().equals("null")){
                sMap.put(uuid,new StuBean(stuID,name,sex,classs,institute,mac));
                request.setAttribute("isSuccess","success");
            }else{
                request.setAttribute("isSuccess","failed");
            }
            request.getRequestDispatcher("/qr/result.jsp").forward(request,response);
        }
    }
}
